**************************************************
********* Figure A4: ********************************
**************************************************
do "do_files/prep_GRACE_data/load_prep_GRACE_data.do"
do "do_files/prep_GRACE_data/ballot_level_prep.do"

***state level variables***************
egen stateyear_latpoppct = mean(latpoppct), by(stateyear)

gen latpop_cat=1 if stateyear_latpoppct<=.1
replace latpop_cat=2 if stateyear_latpoppct>=.100001 & stateyear_latpoppct<=.2

replace latpop_cat=3 if  stateyear_latpoppct>=.200001
replace latpop_cat=0 if latpop_cat==.

* drop any temporary variables that might have been used to generate figure A3_1
local list b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 counter predlawb predlamb counterm lbd2 ubd2 lbd3 ubd3
foreach var of local list {
    capture drop `var'
    if _rc { 
        di in red "Note: failed to drop `var'" 
    } 
}


estsimp probit ballot_latwpres  openmmdproportion latpop_cat postred2010  afampoppct asampoppct latpoppct    tlimit  legprof  distrepubstr  multimem  candperseat allincfmt educcolldeg unemppct  if postred2010==1  | postred2000==1 
gen counter=_n-1
gen predlatw=.
gen lbd2=.
gen ubd2=.
setx mean

set more 1
forvalues i=1(1)100 {
setx openmmdproportion `i'/100
simqi, genpr(p1 p2)
sum p2
replace predlatw=r(mean) if counter==`i'
_pctile p2, p(2.5 97.5)
display r(r1)
display r(r2)
replace lbd2=r(r1) if counter==`i'
replace ubd2=r(r2) if counter==`i'
drop p1 p2
}
drop b1 b2 b3 b4 b5 b6 b7 b8 b9 b10 b11 b12 b13 b14 b15 
estsimp probit ballot_latmpres  openmmdproportion latpop_cat  postred2010 afampoppct asampoppct latpoppct    tlimit  legprof  distrepubstr  multimem  candperseat allincfmt educcolldeg unemppct  if postred2010==1 | postred2000==1 
gen counterm=_n-1
gen predlatm=.
gen lbd3=.
gen ubd3=.
setx mean

set more 1
forvalues i=1(1)100 {
setx openmmdproportion `i'/100
simqi, genpr(p1 p2)
sum p2
replace predlatm=r(mean) if counterm==`i'
_pctile p2, p(2.5 97.5)
display r(r1)
display r(r2)
replace lbd3=r(r1) if counterm==`i'
replace ubd3=r(r2) if counterm==`i'
drop p1 p2
}

twoway (line predlatw counter if counter<=100, sort clcolor(black) clpat(dash) clwidth(medium))(line predlatm counterm if counterm<=100, sort clcolor(black) clpat(solid) clwidth(medium)), legend(region(lcolor(none))) graphregion(fcolor(white))/*
*/ title("Pr. Prob. Latina or Latino on Ballot", size(med) color(black) margin(medium) justification(center))/*
*/ ylabel(0(.01).05, grid glcolor(white)) ytitle("Pr Latina or Latino on Ballot)", size(medsmall) margin(medium)) /*
*/xlabel (0(10)100) xtitle(Open MMD Proportion, size(medsmall) margin(medsmall)) legend(off)legend(on size(small)) legend(label(1 "Latinas") label(2 "Latinos"))


* pausing for users who might be looping through all replication files
pause

